const BaseController = require("../library/base-controller");
const Mapper = require("../database/mapper/user")
const {crud} = require("../library/crud")
const Services = require('ee-core/services');

class UserController extends BaseController {
    init() {
        this.mapper = new Mapper()
    }

    async getBalance(params) {
        let ret = await Services.get('user').getBalance(params.id);
        return this.success(ret)
    }

    async getRecords(params) {
        let ret = await Services.get('user').getRecords(params.id);
        return this.success(ret)
    }

    async withdraw(params) {
        let ret = await Services.get('user').withdraw(params.id, params.money);
        if (ret) {
            return this.success("提现成功")
        } else {
            return this.error("提现失败")
        }
    }

    async login(params) {
        let ret = await Services.get('user').login(params.id);
        if (ret) {
            return this.success("登录成功")
        } else {
            return this.error("登录失败")
        }
    }


    async updateUserMoney() {
        let ret = await Services.get('user').updateUserMoney();
        if (ret) {
            return this.success("更新成功")
        } else {
            return this.error("更新失败")
        }
    }


    async benefitsList() {
        let ret = await Services.get('user').benefitsList();
        return this.success(ret)
    }
}

crud(UserController)

module.exports = UserController
